<?php
namespace app\index\controller;

use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use app\index\controller\FrontBase;
use think\Config;
use think\Request;
use app\common\model\Tips as TipsModel;

use mailer\tp5\Mailer;
use think\Validate;

class Business extends FrontBase
{
	
	    public function index(){
			

        return view('business/index');
    }
	
	    public function save_bak(Request $request){

        $data=$request->post();
		
		     $mail = new PHPMailer();
        $mail->isSMTP();// 使用SMTP服务
        $mail->CharSet = "utf8";// 编码格式为utf8，不设置编码的话，中文会出现乱码
        $mail->Host = "smtp.qiye.163.com";// 发送方的SMTP服务器地址
        $mail->SMTPAuth = true; 
		$mail->isHTML(true);
        $mail->Username = "web@shhorse.com";// 发送方的163邮箱用户名，就是你申请163的SMTP服务使用的163邮箱</span><span style="color:#333333;">
        $mail->Password = "Horse1977";// 发送方的邮箱密码，注意用163邮箱这里填写的是“客户端授权密码”而不是邮箱的登录密码！</span><span style="color:#333333;">
        $mail->SMTPSecure = "ssl";
        $mail->Port = 994;// 163邮箱的ssl协议方式端口号是465/994
        $mail->setFrom("web@shhorse.com");// 设置发件人信息，如邮件格式说明中的发件人，这里会显示为Mailer(xxxx@163.com），Mailer是当做名字显示
        $mail->addAddress("info@shhorse.com");// 设置收件人信息，如邮件格式说明中的收件人，这里会显示为Liang(yyyy@163.com)
        $mail->addReplyTo("web@shhorse.com");// 设置回复人信息，指的是收件人收到邮件后，如果要回复，回复邮件将发送到的邮箱地址
 
		$name=$data['name'];
		$country=$data['country'];
		$phone=$data['phone'];
		$email=$data['email'];
		$company=$data['company'];
		$establish=$data['establish'];
		$business=$data['business'];
		$team=$data['team'];
		$area=$data['area'];
		$funds=$data['funds'];
		$experience=$data['experience'];
		$content=$data['content'];
		
		$body = "";  
$body.="<p>Name: $name</p>";
$body.="<p>Country: $country</p>";
$body.="<p>Phone: $phone</p>";
$body.="<p>Email: $email</p>";
$body.="<p>Company: $company</p>";
$body.="<p>Year of establish: $establish</p>";
$body.="<p>Years of Import business: $business</p>";
$body.="<p>Number of Sales team: $team</p>";
$body.="<p>Warehouse area: $area</p>";
$body.="<p>Amount of specialized funds: $funds</p>";
$body.="<p>Industry experience: $experience</p>";
$body.="<p>Content: $content</p>";

 
        $mail->Subject = "Contact Us";// 邮件标题
        $mail->Body = $body;// 邮件正文
            
        if(!$mail->send()){// 发送邮件

        echo 0; die();
 
        }else{
           echo 1;
        }
	 
 
 
      
      
    }



    public function save(Request $request){

        if(!$request->isPost()){
            echo json_encode(["state"=>'err','message'=>'Permission denied']);exit;
        }
        $data=$request->post();
        $name=$data['name'];
        $country=$data['country'];
        $phone=$data['phone'];
        $email=$data['email'];
        $company=$data['company'];
        $establish=$data['establish'];
        $business=$data['business'];
        $team=$data['team'];
        $area=$data['area'];
        $funds=$data['funds'];
        $experience=$data['experience'];
        $content=$data['content'];

        $body = "";
        $body.="<p>Name: $name</p>";
        $body.="<p>Country: $country</p>";
        $body.="<p>Phone: $phone</p>";
        $body.="<p>Email: $email</p>";
        $body.="<p>Company: $company</p>";
        $body.="<p>Year of establish: $establish</p>";
        $body.="<p>Years of Import business: $business</p>";
        $body.="<p>Number of Sales team: $team</p>";
        $body.="<p>Warehouse area: $area</p>";
        $body.="<p>Amount of specialized funds: $funds</p>";
        $body.="<p>Industry experience: $experience</p>";
        $body.="<p>Content: $content</p>";



        $mailer = Mailer::instance();
        $mailer->from('13482021417@163.com', "user")
            ->to('info@shhorse.com')
            //->to('1427047861@qq.com')
            ->subject('来自www.horseen.com的留言')
            ->text($body)
            ->send();
        echo "1";
        exit;
        //echo json_encode(['state'=>'ok','message'=>'Succeed to be sent']);exit;


    }

    public function agent(){

        $agents = TipsModel::order('id asc')->where('type','7')->select();
        $this->param['agents'] = $agents;

        return view('',$this->param);
    }
}